import axios from "axios";

class WQRequest {
    instance;
    Interceptors;
    constructor(config) {
        this.instance = axios.create(config);
        this.Interceptors = config.Interceptors;
        this.instance.interceptors.request.use(config.Interceptors.requestInterceptor, config.Interceptors.requestInterceptorCatch);
        this.instance.interceptors.response.use(config.Interceptors.responseInterceptor, config.Interceptors.responseInterceptorCatch);
        this.instance.interceptors.request.use(
            (config) => {
                return config;
            },
            (err) => {
                return err;
            }
        );
        this.instance.interceptors.response.use(
            (config) => {
                return config.data;
            },
            (err) => {
                return err;
            }
        );
    }
    request(config) {
        return new Promise((reslove, reject) => {
            this.instance
                .request(config)
                .then((res) => {
                    reslove(res);
                })
                .catch((err) => {
                    reject(err);
                });
        });
    }
    get(config) {
        return this.request({
            ...config,
            method: "get"
        });
    }
    post(config) {
        return this.request({
            ...config,
            method: "post"
        });
    }
}

export default WQRequest;
